package com.ikun.admin.modules.auth.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @ClassName SecurityUtil
 * @Description:
 * @CreateDate: 2024/6/1 0:54
 */
public class SecurityUtil {
    public static Long getCurrentUserId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.isAuthenticated()) {
            Object principal = authentication.getPrincipal();
            return Long.parseLong(principal.toString()) ;
        }
        return null;
    }


}
